package test

import (
	"github.com/gin-gonic/gin"
	"shopstar/global"
	"shopstar/util"
)

func GenJwt(ctx *gin.Context) {
	token, _ := util.JWT.GenerateToken(global.JwtKey, map[string]interface{}{
		"member_id": "1",
		util.VKey:   "1",
	})

	ctx.String(200, token)
}

func ValJwt(ctx *gin.Context) {
	//token, _ := ctx.Get("token")
	//token := ctx.Request.Header.Get("x-token")
	//fmt.Println(token)
	ctx.String(200, "ok")
}

func RefJwt(ctx *gin.Context) {
	token, err := util.JWT.RefreshToken(ctx.Request.Header.Get("x-token"), global.JwtKey)
	if err != nil {
		ctx.String(200, err.Error())
		return
	}

	ctx.String(200, token)
}
